from playhouse.pool import PooledMySQLDatabase
from playhouse.shortcuts import ReconnectMixin

# mysql gone away

class ReconnectMysqlDatabase(ReconnectMixin, PooledMySQLDatabase):
    pass


MYSQL_DB = "mxshop_user"
MYSQL_HOST = "127.0.0.1"
MYSQL_PORT = 5931
MYSQL_USER = "root"
MYSQL_PASSWORD = "admin123"


DB = ReconnectMysqlDatabase(MYSQL_DB, host=MYSQL_HOST, port=MYSQL_PORT, user=MYSQL_USER, password=MYSQL_PASSWORD)


import json

# import nacos

from loguru import logger


# 使用peewee的连接池， 使用ReconnectMixin来防止出现连接断开查询失败
class ReconnectMysqlDatabase(ReconnectMixin, PooledMySQLDatabase):
    pass


NACOS = {
    "Host": "192.168.0.104",
    "Port": 8848,
    "NameSpace": "c1872978-d51c-4188-a497-4e0cd20b97d5",
    "User": "nacos",
    "Password": "nacos",
    "DataId": "user-srv.json",
    "Group": "dev"
}

# client = nacos.NacosClient(f'{NACOS["Host"]}:{NACOS["Port"]}', namespace=NACOS["NameSpace"],
#                            username=NACOS["User"],
#                            password=NACOS["Password"])
#
# # get config
# data = client.get_config(NACOS["DataId"], NACOS["Group"])
# data = json.loads(data)
# logger.info(data)


# def update_cfg(args):
#     print("配置产生变化")
#     print(args)
#
# # consul的配置
# CONSUL_HOST = data["consul"]["host"]
# CONSUL_PORT = data["consul"]["port"]
#
# # 服务相关的配置
# SERVICE_NAME = data["name"]
# SERVICE_TAGS = data["tags"]

# consul的配置
CONSUL_HOST = "127.0.0.1"
CONSUL_PORT = 8500

# 服务相关的配置
SERVICE_NAME = "user-srv"
SERVICE_TAGS = ["python", "boddy", "srv", "mxshop"]

